﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SterlingReportImporter.Properties;
using Algobox.JuicyLib.Apps.Sterling;

namespace SterlingReportImporter
{
    class Program
    {
        static void Main(string[] args)
        {
            string process = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            Console.WriteLine("Starting " + process);
            Console.WriteLine("Using config file: " + AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            List<string> ignoreAccounts = Settings.Default.IGNOREACCOUNTS.Split(',').ToList();
            List<string> stockFiles = Settings.Default.STOCK_FILENAMES.Split(',').ToList();
            List<string> optionsFiles = Settings.Default.OPTIONS_FILENAMES.Split(',').ToList();

            // if DROP exchange is found and account exists in this csv then map it to the supplied exchange code
            Dictionary<string, string> accountExchangeMap = new Dictionary<string, string>();
            Settings.Default.DROP_EXCHANGE_MAP.Split(',').ToList().ForEach((a) =>
            {
                var b = a.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (b.Length == 2)
                {
                    accountExchangeMap.Add(b[0], b[1]);
                }
            });

            // exchangeBrokers is used for mapping a broker code to exchange and allowing it to be imported
            List<string> exchangeBrokerCodes = Settings.Default.EXCHANGE_EXECBROKER.Split(',').ToList();


            // default connection string
            // Data Source=localhost;Initial Catalog=LiquidView;Integrated Security=True

            // local connection string over VPN
            // Data Source=172.20.99.233;Initial Catalog=LiquidView;User ID=user;Password=blah

            using (SterlingTradeImporter2 dropper =
                new SterlingTradeImporter2(
                    process,
                    Settings.Default.ARCHIVEDIR,
                    Settings.Default.LV_DBConn))
            {
                Console.WriteLine("Importing Sterling trade files");

                dropper.RunDailyFiles(
                    Settings.Default.STI_FTPDestinationURI,
                    Settings.Default.STI_FTPUsername,
                    Settings.Default.STI_FTPPassword,
                    ignoreAccounts,
                    stockFiles,
                    optionsFiles,
                    accountExchangeMap,
                    exchangeBrokerCodes);

            }

            //using (SterlingTradeImporter dropper =
            //    new SterlingTradeImporter(
            //        process, 
            //        Settings.Default.ARCHIVEDIR,
            //        Settings.Default.LV_DBConn))
            //{
            //    Console.WriteLine("Importing Sterling trade files");
                
            //    dropper.RunDailyTrades(
            //        Settings.Default.STI_FTPDestinationURI,
            //        Settings.Default.STI_FTPUsername,
            //        Settings.Default.STI_FTPPassword,
            //        ignoreAccounts);

            //}
        }
    }
}
